package com.example.snackfood.services.impl;

import com.example.snackfood.dao.SnackFoodCommentDao;
import com.example.snackfood.entity.Comments;
import com.example.snackfood.services.IsnackFoodCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-23 13:19
 **/


@Service
public class SnackFoodCommentService implements IsnackFoodCommentService {

    @Autowired
    private SnackFoodCommentDao snackFoodCommentDao;

    /**
     * 成功加入评论
     * @param comments
     */
    public void add(Comments comments) {
        snackFoodCommentDao.add(comments);
    }


    /**
     * 查
     * @param id
     * @return
     */
    public Comments selectCommentById(Long id) {
        Criteria criteriaid=Criteria.where("id").is(id);
        Criteria orCriteria = new Criteria();
        orCriteria.orOperator(criteriaid);
        Query query=new Query(orCriteria);
        return  snackFoodCommentDao.selectCommentById(query);
    }

    /**
     * 删除评论
     * @param id
     */
    @Override
    public void deleteComment(Long id) {
        Criteria criteriaid=Criteria.where("id").is(id);
        Criteria orCriteria = new Criteria();
        orCriteria.orOperator(criteriaid);
        Query query=new Query(orCriteria);
        snackFoodCommentDao.deleteComment(query);
    }
}
